Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
heap_allocator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/heap_allocator.h
10//! @brief Heap allocator implementation.
11
12#ifndef ROC_CORE_HEAP_ALLOCATOR_H_
13#define ROC_CORE_HEAP_ALLOCATOR_H_
14
15#include "roc_core/atomic.h"
16#include "roc_core/iallocator.h"
18
19namespace roc {
20namespace core {
21
22//! Heap allocator implementation.
23//!
24//! Uses global operator new[] and operator delete[].
25//!
26//! The memory is always maximum aligned. Thread-safe.
27class HeapAllocator : public IAllocator, public NonCopyable<> {
28public:
30
31 //! Allocate memory.
32 virtual void* allocate(size_t size);
33
34 //! Deallocate previously allocated memory.
35 virtual void deallocate(void*);
36
37 //! Get number of allocated blocks.
38 size_t num_allocations() const;
39
40private:
41 Atomic num_allocations_;
42};
43
44} // namespace core
45} // namespace roc
46
47#endif // ROC_CORE_HEAP_ALLOCATOR_H_
Atomic integer.
Atomic integer.
Definition: atomic.h:21
Heap allocator implementation.
size_t num_allocations() const
Get number of allocated blocks.
virtual void * allocate(size_t size)
Allocate memory.
virtual void deallocate(void *)
Deallocate previously allocated memory.
Memory allocator interface.
Definition: iallocator.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Memory allocator interface.
Root namespace.
Non-copyable object.